VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
  Persistable = 0  'NotPersistable
  DataBindingBehavior = 0  'vbNone
  DataSourceBehavior  = 0  'vbNone
  MTSTransactionMode  = 0  'NotAnMTSObject
END
Attribute VB_Name = "clsCreateXMLRes"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Option Explicit

Public Function XMLCreateResponseFile() As String

    Dim xmldoc                  As MSXML2.DOMDocument
    Dim ProcessInst             As MSXML2.IXMLDOMProcessingInstruction
    
    Dim nKeytax                 As MSXML2.IXMLDOMNode
    Dim nResponse               As MSXML2.IXMLDOMNode
    
    Dim nlKeytax                As MSXML2.IXMLDOMNodeList
    
    'Response
    Dim ellKeytax               As MSXML2.IXMLDOMElement
    Dim ellResponse             As MSXML2.IXMLDOMElement
    Dim ellSARSAppID            As MSXML2.IXMLDOMElement
    Dim ellITAreaCode           As MSXML2.IXMLDOMElement
    Dim ellDirectiveNumber      As MSXML2.IXMLDOMElement
    Dim ellIssueDate            As MSXML2.IXMLDOMElement
    Dim ellDirStartDate         As MSXML2.IXMLDOMElement
    Dim ellDirEndDate           As MSXML2.IXMLDOMElement
    Dim ellTaxFreePortion       As MSXML2.IXMLDOMElement
    Dim ellGrossAmountPAYE      As MSXML2.IXMLDOMElement
    Dim ellDirectiveType        As MSXML2.IXMLDOMElement
    Dim ellAssessedTaxAmt       As MSXML2.IXMLDOMElement
    Dim ellIT88RefNo            As MSXML2.IXMLDOMElement
    
    
    'Must always specify, depending on what response file you are working with
    nTypeResponse = "02"
    
    On Error GoTo PROC_ERROR
    
    Set xmldoc = New MSXML2.DOMDocument
    
    'get header xml file
    Dim sGetXMLHeader           As Object
    Dim strXMLHeader            As String
    Set sGetXMLHeader = CreateObject("GenericXMLHeader.clsGetXMLHeader")
    'GetXMLHeader(ByVal nReqSeqNum As String, ByVal nTypeResponse As String,ByRef nReferenceId As String, _
    'ByRef nComId As String, ByRef nBuId As String, ByRef nNewMessageID As String, ByRef sFormType As String)
    strXMLHeader = sGetXMLHeader.GetXMLHeader(nReqSeqNum, nTypeResponse, nReferenceId, nComId, nBuId, nNewMessageID, sFormType, ServerName)
    'Tina: to many paramaters being passed to dll
    'strXMLHeader = sGetXMLHeader.GetXMLHeader(nReqSeqNum, nTypeResponse, nReferenceId, nComId, nBuId, nNewMessageID, sFormType)
    xmldoc.loadXML (strXMLHeader)
    
    Set nKeytax = xmldoc.selectSingleNode("KeyTax")
    Set xmldoc.documentElement = nKeytax
    
    Set nlKeytax = xmldoc.getElementsByTagName("KeyTax")
    Set ellKeytax = nlKeytax.Item(0)

     
    'Add Response XML data
    Set nResponse = xmldoc.createElement("Response")
    Call nKeytax.appendChild(nResponse)
    
    Set ellResponse = nResponse
    Call ellResponse.setAttribute("Form", sFormType)
    Call nKeytax.appendChild(ellResponse)
    
    Set ellSARSAppID = xmldoc.createElement("SARSAppID")
    ellSARSAppID.nodeTypedValue = nApplID
    Call nResponse.appendChild(ellSARSAppID)
    
    Set ellITAreaCode = xmldoc.createElement("ITAreaCode")
    ellITAreaCode.nodeTypedValue = nAreaCode
    Call nResponse.appendChild(ellITAreaCode)
    
    Set ellDirectiveNumber = xmldoc.createElement("DirectiveNumber")
    ellDirectiveNumber.nodeTypedValue = nDirNumber
    Call nResponse.appendChild(ellDirectiveNumber)
    
    Set ellIssueDate = xmldoc.createElement("IssueDate")
    Call ConvertDate(dIssueDate)
    ellIssueDate.nodeTypedValue = dIssueDate
    Call nResponse.appendChild(ellIssueDate)
    
    Set ellDirStartDate = xmldoc.createElement("DirStartDate")
    Call ConvertDate(dStartDate)
    ellDirStartDate.nodeTypedValue = dStartDate
    Call nResponse.appendChild(ellDirStartDate)
    
    Set ellDirEndDate = xmldoc.createElement("DirEndDate")
    Call ConvertDate(dEndDate)
    ellDirEndDate.nodeTypedValue = dEndDate
    Call nResponse.appendChild(ellDirEndDate)
    
    Set ellTaxFreePortion = xmldoc.createElement("TaxFreePortion")
    ellTaxFreePortion.nodeTypedValue = nTaxFree
    Call nResponse.appendChild(ellTaxFreePortion)
    
    Set ellGrossAmountPAYE = xmldoc.createElement("GrossAmountPAYE")
    ellGrossAmountPAYE.nodeTypedValue = nGrossPAYE
    Call nResponse.appendChild(ellGrossAmountPAYE)
    
    Set ellDirectiveType = xmldoc.createElement("DirectiveType")
    Call ellDirectiveType.setAttribute("Type", sDirType)
    Call nResponse.appendChild(ellDirectiveType)
    
'    Set ellAssessedTaxAmt = xmldoc.createElement("AssessedTaxAmt")
'    ellAssessedTaxAmt.nodeTypedValue = nAssAmt
'    Call nResponse.appendChild(ellAssessedTaxAmt)
    
    'Changed by shane on 28/10/2002
    'Used same element so as not to create a big change on LCB's side for TOTAL TAX, PENALTY AND INTEREST
    Set ellAssessedTaxAmt = xmldoc.createElement("AssessedTaxAmt")
    ellAssessedTaxAmt.nodeTypedValue = nTotalAmt
    Call nResponse.appendChild(ellAssessedTaxAmt)
   
    Set ellIT88RefNo = xmldoc.createElement("IT88RefNo")
    ellIT88RefNo.nodeTypedValue = nIT88No
    Call nResponse.appendChild(ellIT88RefNo)
    
    
    XMLCreateResponseFile = CStr(xmldoc.xml)

'clean up
Set sGetXMLHeader = Nothing
Set xmldoc = Nothing
Set ProcessInst = Nothing
Set nKeytax = Nothing
Set nResponse = Nothing
Set nlKeytax = Nothing
Set ellKeytax = Nothing
Set ellSARSAppID = Nothing
Set ellITAreaCode = Nothing
Set ellDirectiveNumber = Nothing
Set ellIssueDate = Nothing
Set ellDirStartDate = Nothing
Set ellDirEndDate = Nothing
Set ellTaxFreePortion = Nothing
Set ellGrossAmountPAYE = Nothing
Set ellDirectiveType = Nothing
Set ellAssessedTaxAmt = Nothing
Set ellIT88RefNo = Nothing

PROC_EXIT:
  Exit Function

PROC_ERROR:
  Err.Raise Err.Number, _
            "clsCreateXMLRes/XMLCreateResponseFile", _
            Err.Description
            
Resume PROC_EXIT
  
End Function 'XMLCreateResponseFile
Public Function CreateXmlVersionDtdHeader() As String
    Dim strXmlString As String

    strXmlString = "<?xml version=""1.0"" encoding=""UTF-8""?>" & Chr(13)
    strXmlString = strXmlString & "<!DOCTYPE KeyTax SYSTEM ""C:\Shane\Projects\LCB\FormB\XML Docs\FormB_Response.dtd"">" & Chr(13)

    CreateXmlVersionDtdHeader = strXmlString

End Function 'CreateXmlVersionDtdHeader
Public Function ConvertDate(ByRef dtDate As String)
'2002-01-22
Dim dtYear As String
Dim dtMonth As String
Dim dtDay As String

dtYear = Year(dtDate)
dtMonth = Month(dtDate)
dtDay = Day(dtDate)
If Len(dtMonth) = 1 Then
    dtMonth = "0" & dtMonth
End If
If Len(dtDay) = 1 Then
    dtDay = "0" & dtDay
End If
        

dtDate = dtYear & dtMonth & dtDay

End Function 'ConvertDate


